<?php

class SING_other {

    var $initated = false;
    var $init_db = true;

    public function __construct() {
        $this->_init();
    }

    public function _init() {
        if (!$this->initated) {
            $this->_init_db();
            //$this->_init_setting();
            //$this->_init_user();
            //$this->_init_session();
            //$this->_init_mobile();
            //$this->_init_cron();
            //$this->_init_misc();
        }
        $this->initated = true;
    }

    private function _init_db() {
        global $_G;
        if ($this->init_db) {
            $driver = function_exists('mysql_connect') ? 'db_driver_mysql' : 'db_driver_mysqli';
            if (getglobal('config/db/slave')) {
                $driver = function_exists('mysql_connect') ? 'db_driver_mysql_slave' : 'db_driver_mysqli_slave';
            }
            DB::init($driver, $_G['config']['db']);
        }
    }

    private function _init_setting() {
        
    }

    private function _init_user() {
        //兼容老版本的登录
        //var_dump(getglobal('lasttime'));
        $clientkey = getcookie('authkey');

        list($usr, $password, $authkey) = explode("\t", SING_auth($clientkey, 'DECODE', getglobal('cookiepre', 'config/cookie')));

        //OA系统用户部分
        $User = C::t('init_user')->getUsr($usr);
        if ($User['password'] == md5($password . $User['rand'])) {

            setglobal('uid', $User['memberid']);
            setglobal('username', $User['username']);
            setglobal('relname', $User['relname']);
            setglobal('adminid', 1);

            setglobal('groupid', $User['groupid']);
            setglobal('deid', $User['deid']);

            setglobal('logintime', $User['logintime']);
            setglobal('lasttime', $User['lasttime']);

            setglobal('relname', $User['relname']);
            setglobal('status', $User['status']);
            //setglobal('adminid', getglobal('adminid', 'member'));
        }
    }

    private function _init_session() {
        //session_start();
    }

    private function _init_mobile() {
        
    }

    private function _init_cron() {
        
    }

    private function _init_misc() {
        
    }

}
